﻿using System;

namespace Csharp基础飞行棋
{
	class Util
	{
		public static int w = 50;
		public static int h = 30;
		public static string wall = "墙";
		public static string nullCellIcon = "  ";
		public static string normalCellIcon = "格";
		public static string bombCellIcon = "炸";
		public static string pauseCellIcon = "停";
		public static string tunnelCellIcon = "隧";
		public static string overLapIcon = "叠";
		public static string playerIcon = "我";
		public static string aiIcon = "电";
		public static string GetCellIcon(E_CellType type)
		{
			switch (type)
			{
				case E_CellType.Normal:
					return normalCellIcon;
				case E_CellType.Bomb:
					return bombCellIcon;
				case E_CellType.Pause:
					return pauseCellIcon;
				case E_CellType.Tunnel:
					return tunnelCellIcon;
				case E_CellType.NullCellIcon:
					return nullCellIcon;
				default:
					return "bug?";
			}
		}
		public static ConsoleColor GetCellColor(E_CellType type)
		{
			switch (type)
			{
				case E_CellType.Normal:
					return ConsoleColor.White;
				case E_CellType.Bomb:
					return ConsoleColor.Red;
				case E_CellType.Pause:
					return ConsoleColor.Blue;
				case E_CellType.Tunnel:
					return ConsoleColor.Yellow;
				case E_CellType.NullCellIcon:
					return ConsoleColor.Cyan;
				default:
					Console.WriteLine("bug?");
					return ConsoleColor.DarkMagenta;
			}
		}
		public static string GetCharacterIcon(CharacterType type)
		{
			switch (type)
			{
				case CharacterType.Player:
					return playerIcon;
				case CharacterType.Ai:
					return aiIcon;
				default:
					return "bug?";
			}
		}
		public static ConsoleColor GetCharacterColor(CharacterType type)
		{
			switch (type)
			{
				case CharacterType.Player:
					return ConsoleColor.Magenta;
				case CharacterType.Ai:
					return ConsoleColor.Cyan;
				default:
					Console.WriteLine("bug?");
					return ConsoleColor.Red;
			}
		}
	}
	
	
	
	
	
	class Program
	{
		private static int w = Util.w;
		private static int h = Util.h;
		private static E_SceneType nowSceneType;

		static void Main(string[] args)
		{
			#region 1.控制台初始化
			ConsoleInit(w, h);
			#endregion
			#region 2.场景选择相关
			nowSceneType = E_SceneType.Start;
			while (true)
			{
				switch (nowSceneType)
				{
					case E_SceneType.Start:
						Console.Clear();
						//Console.WriteLine("开始场景");
						StartScene(w, h, ref nowSceneType);
						break;
					case E_SceneType.Game:
						Console.Clear();
						//Console.WriteLine("游戏场景");
						GameScene(w, h, ref nowSceneType);
						break;
					case E_SceneType.End:
						Console.Clear();
						//Console.WriteLine("结束场景");
						StartScene(w, h, ref nowSceneType);
						break;
				}
			}
			#endregion
		}
		
		#region 1.控制台初始化
		static void ConsoleInit(int w, int h)
		{
			Console.CursorVisible = false;
			Console.SetWindowSize(w, h);
			Console.SetBufferSize(w, h);
		}
		#endregion

		#region 3.开始场景逻辑 + 8.结束场景逻辑
		static void StartScene(int w, int h, ref E_SceneType nowSceneType)
		{
			Console.SetCursorPosition(w / 2 - 10, 12);
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.WriteLine("---按 f/F 键确认---");
			Console.SetCursorPosition(w / 2 - 15, 14);
			Console.WriteLine("---输入没反应？记得切换输入法---");
			Console.SetCursorPosition(w / 2 - 10, 15);
			Console.WriteLine("---w/a/s/d进行移动---");

			Console.ForegroundColor = ConsoleColor.White;
			Console.SetCursorPosition(nowSceneType == E_SceneType.Start ? w / 2 - 6 : w / 2 - 5, 4);
			Console.WriteLine(nowSceneType == E_SceneType.Start ? "花火的飞行棋" : "Game  Over");
			int selectItem = 0;
			bool isOver = false;
			while (!isOver)
			{
				Console.ForegroundColor = selectItem == 0 ? ConsoleColor.Red : ConsoleColor.White;
				
				if (selectItem == 0)
				{
					Console.SetCursorPosition(nowSceneType == E_SceneType.Start ? w / 2 - 6 : w / 2 - 7, 7);
					Console.WriteLine(nowSceneType == E_SceneType.Start ? "->开始游戏" : "->返回主菜单");
				}
				else
				{
					Console.SetCursorPosition(nowSceneType == E_SceneType.Start ? w / 2 - 6 : w / 2 - 7, 7);
					Console.WriteLine(nowSceneType == E_SceneType.Start ? "  开始游戏" : "  返回主菜单");
				}
				Console.ForegroundColor = selectItem == 1 ? ConsoleColor.Red : ConsoleColor.White;
				if (selectItem == 1)
				{
					Console.SetCursorPosition(w / 2 - 6, 9);
					Console.WriteLine("->退出游戏");
				}
				else
				{
					Console.SetCursorPosition(w / 2 - 6, 9);
					Console.WriteLine("  退出游戏");
				}
				switch (Console.ReadKey(true).Key)
				{
					case ConsoleKey.W:
						selectItem -= 1;
						if (selectItem < 0)
						{
							selectItem = 1;
						}
						break;
					case ConsoleKey.S:
						selectItem += 1;
						selectItem %= 2;
						break;
					case ConsoleKey.F:
						if (selectItem == 0)
						{
							nowSceneType = nowSceneType == E_SceneType.Start ? E_SceneType.Game : E_SceneType.Start;
							isOver = true;
						}
						else if (selectItem == 1)
						{
							Environment.Exit(0);
						}
						else
						{
							Console.WriteLine("bug?");
						}
						break;
				}
			}
		}
		#endregion

		#region 游戏场景逻辑
		static void GameScene(int w, int h, ref E_SceneType nowSceneType)
		{
			// 不变的部分
			DrawWall(w, h);

			// 绘制地图
			// 15x10
			//int map_w = 19;
			int map_w = (new Random()).Next(10, 19);
			int map_h = 10;
			Map map = new Map(14, 2, map_w * map_h / 2);
			//map.Init();
			map.draw();
			// 绘制玩家
			Character player = new Character(
				CharacterType.Player,
				0,
				Util.GetCharacterIcon(CharacterType.Player), 
				Util.GetCharacterColor(CharacterType.Player)
				);
			Character ai = new Character(
				CharacterType.Ai,
				0,
				Util.GetCharacterIcon(CharacterType.Ai), 
				Util.GetCharacterColor(CharacterType.Ai)
				);

			DrawCharacter(player, ai, map);

			// 游戏场景循环
			bool isOver = false;
			while (true)
			{
				if (CharacterMove(w, h, ref player, ref ai, map, ref nowSceneType))
				{
					 break;
				}
				if (CharacterMove(w, h, ref ai, ref player, map, ref nowSceneType))
				{
					break;
				}
			}
		}

		static void DrawCharacter(Character player, Character ai, Map map)
		{
			if (player.nowIndex_ == ai.nowIndex_)
			{
				Cell cell = map.cells_[player.nowIndex_];
				Console.SetCursorPosition(cell.pos_.x_, cell.pos_.y_);
				Console.ForegroundColor = ConsoleColor.Green;
				Console.Write("{0}", Util.overLapIcon);
			}
			else
			{
				player.Draw(map);
				ai.Draw(map);
			}
		}
		static void ClearMsg(int h)
		{
			Console.SetCursorPosition(2, h - 2);
			Console.Write("                                             ");
			Console.SetCursorPosition(2, h - 3);
			Console.Write("                                             ");
			Console.SetCursorPosition(2, h - 4);
			Console.Write("                                             ");
			Console.SetCursorPosition(2, h - 5);
			Console.Write("                                             ");
		}
		static bool ThrowDice(int w, int h, ref Character character, ref Character other, Map map)
		{
			// 清除旧信息
			ClearMsg(h);
			// 设置字体颜色
			Console.ForegroundColor = Util.GetCharacterColor(character.type_);
			// 是否暂停
			if (character.isPause)
			{
				Console.SetCursorPosition(3, h - 5);
				if (character.type_ == CharacterType.Player)
				{
					Console.WriteLine("{0}暂停一回合", "你");
				}

				else
				{
					Console.WriteLine("{0}暂停一回合", "AI");
				}
				Console.SetCursorPosition(3, h - 4);
				Console.WriteLine("请你按任意键继续");
				character.isPause = false;
				return false;
			}
			// 扔骰子
			Random r = new Random();
			int dice = r.Next(1, 7);
			Console.SetCursorPosition(3, h - 5);
			if (character.type_ == CharacterType.Player)
			{
				Console.WriteLine("你扔出了[{0}]点", dice);
			}
			else
			{
				Console.WriteLine("电脑扔出了[{0}]点", dice);
			}
			character.nowIndex_ += dice;
			if (character.nowIndex_ >= map.cells_.Length - 1)
			{
				character.nowIndex_ = map.cells_.Length - 1;
				Console.SetCursorPosition(3, h - 4);
				Console.Write("                                             ");
				Console.SetCursorPosition(3, h - 3);
				Console.Write("                                             ");
				Console.SetCursorPosition(3, h - 2);
				Console.Write("                                             ");
				System.Threading.Thread.Sleep(1000);
				// 绘制地图
				map.draw();
				// 绘制玩家
				DrawCharacter(character, other, map);
				Console.ForegroundColor = ConsoleColor.Yellow;
				Console.SetCursorPosition(3, h - 4);
				Console.Write(character.type_ == CharacterType.Player ? 
					"恭喜你，你到达了终点，获得了胜利！" : "电脑到达了终点，你失败了，再接再厉！"
					);
				Console.SetCursorPosition(3, h - 3);
				Console.Write("按下任意键继续");
				return true;
			}
			Func(ref character, ref other, map, 0);
			Console.SetCursorPosition(3, h - 3);
			if (character.type_ == CharacterType.Player)
			{
				Console.WriteLine("请按任意键，让电脑开始扔骰子");
			}
			else
			{
				Console.WriteLine("请按任意键，让你开始扔骰子");
			}
			return false;
		}
		static bool CharacterMove(int w, int h, ref Character character, ref Character other, Map map, ref E_SceneType nowSceneType)
		{
			// 检测输入
			Console.ReadKey(true);
			// 扔骰子
			// 绘制地图
			map.draw();
			// 绘制玩家
			DrawCharacter(character, other, map);
			// 判断是否结束游戏
			bool isOver = ThrowDice(w, h, ref character, ref other, map);
			if (isOver)
			{
				Console.ReadKey(true);
				nowSceneType = E_SceneType.End;
			}
			return isOver;
		}
		static void Func(ref Character character, ref Character other, Map map, int depth)
		{

			if (depth > 0 && (map.cells_[character.nowIndex_].type_ == E_CellType.Normal ||
				map.cells_[character.nowIndex_].type_ == E_CellType.Bomb))
			{
				return;
			}
			if (depth > 0)
			{
				ConsoleColor temp = Console.ForegroundColor;
				Console.ForegroundColor = ConsoleColor.Red;
				Console.SetCursorPosition(3, h - 2);
				if (character.type_ == CharacterType.Player)
				{
					Console.WriteLine("你连续触发事件... 请稍等");
				}
				else
				{
					Console.WriteLine("AI连续触发事件... 请稍等");
				}
				System.Threading.Thread.Sleep(1000);
				Console.SetCursorPosition(3, h - 2);
				Console.Write("                                             ");
				Console.ForegroundColor = temp;
			}
			Random r = new Random();
			int dice;
			switch (map.cells_[character.nowIndex_].type_)
			{
				case E_CellType.Normal:
					// 普通格子
					Console.SetCursorPosition(3, h - 4);
					if (character.type_ == CharacterType.Player)
					{
						Console.WriteLine("你到达一个安全位置");
					}
					else
					{
						Console.WriteLine("电脑到达一个安全位置");
					}
					break;
				case E_CellType.Bomb:
					// 炸弹格子
					character.nowIndex_ -= 5;
					if (character.nowIndex_ < 0)
					{
						character.nowIndex_ = 0;
					}
					Console.SetCursorPosition(3, h - 4);
					if (character.type_ == CharacterType.Player)
					{
						Console.WriteLine("你触发了炸弹，后退5步");
					}
					else
					{
						Console.WriteLine("电脑触发了炸弹，后退5步");
					}

					Func(ref character, ref other, map, depth + 1);
					break;
				case E_CellType.Pause:
					// 暂停格子
					character.isPause = true;
					Console.SetCursorPosition(3, h - 4);
					if (character.type_ == CharacterType.Player)
					{
						Console.WriteLine("你到达一个暂停点，暂停一回合");
					}
					else
					{
						Console.WriteLine("电脑到达一个暂停点，暂停一回合");
					}
					break;
				case E_CellType.Tunnel:
					// 时空隧道格子
					dice = r.Next(1, 4);
					if (dice == 1)
					{
						//后退
						character.nowIndex_ -= 5;
						if (character.nowIndex_ < 0)
						{
							character.nowIndex_ = 0;
						}
						Console.SetCursorPosition(3, h - 4);
						if (character.type_ == CharacterType.Player)
						{
							Console.WriteLine("你进入了时空隧道...random: 后退5步");
						}
						else
						{
							Console.WriteLine("电脑进入了时空隧道...random: 后退5步");
						}

						Func(ref character, ref other, map, depth + 1);
					}
					else if (dice == 2)
					{
						// 暂停
						character.isPause = true;
						Console.SetCursorPosition(3, h - 4);
						if (character.type_ == CharacterType.Player)
						{
							Console.WriteLine("你进入了时空隧道...random: 暂停一回合");
						}
						else
						{
							Console.WriteLine("电脑进入了时空隧道...random: 暂停一回合");
						}
					}
					else
					{
						// 交换
						int temp = character.nowIndex_;
						character.nowIndex_ = other.nowIndex_;
						other.nowIndex_ = temp;
						Console.SetCursorPosition(3, h - 4);
						if (character.type_ == CharacterType.Player)
						{
							Console.WriteLine("你进入了时空隧道...random: 你与电脑交换位置");
						}
						else
						{
							Console.WriteLine("你进入了时空隧道...random: 电脑与你交换位置");
						}
						Func(ref character, ref other, map, depth + 1);
					}
					break;
			}
		}
		#endregion

		#region 4.绘制不变的内容 (不变的红墙等)
		static void DrawWall(int w, int h)
		{
			Console.ForegroundColor = ConsoleColor.Red;
			for (int i = 0; i < w; i += 2)
			{
				Console.SetCursorPosition(i, 0);
				Console.Write(Util.wall);
				Console.SetCursorPosition(i, h - 11);
				Console.Write(Util.wall);
				Console.SetCursorPosition(i, h - 6);
				Console.Write(Util.wall);
				Console.SetCursorPosition(i, h - 1);
				Console.Write(Util.wall);
			}

			for (int i = 0; i < h; i++)
			{
				Console.SetCursorPosition(0, i);
				Console.Write(Util.wall);
				Console.SetCursorPosition(w - 2, i);
				Console.Write(Util.wall);
			}
			// 其他
			Console.ForegroundColor = ConsoleColor.White;
			Console.SetCursorPosition(3, 3);
			Console.WriteLine("{0}", "飞行棋");
			Console.ForegroundColor = ConsoleColor.White;
			Console.SetCursorPosition(3, h - 10);
			Console.WriteLine("{0}: 普通格子", Util.normalCellIcon);

			Console.ForegroundColor = ConsoleColor.Blue;
			Console.SetCursorPosition(3, h - 9);
			Console.WriteLine("{0}: 暂停格子", Util.pauseCellIcon);
			Console.ForegroundColor = ConsoleColor.Red;
			Console.SetCursorPosition(3 + w / 2, h - 9);
			Console.WriteLine("{0}: 炸弹格子", Util.bombCellIcon);
			Console.ForegroundColor = ConsoleColor.White;
			Console.SetCursorPosition(3, h - 8);
			Console.WriteLine("{0}: 时空隧道格子", Util.tunnelCellIcon);
			Console.ForegroundColor = Util.GetCharacterColor(CharacterType.Player);
			Console.SetCursorPosition(3, h - 7);
			Console.WriteLine("{0}: 玩家", Util.playerIcon);
			Console.ForegroundColor = Util.GetCharacterColor(CharacterType.Ai);
			Console.SetCursorPosition(3 + 10, h - 7);
			Console.WriteLine("{0}: AI", Util.aiIcon);
			Console.ForegroundColor = ConsoleColor.Green;
			Console.SetCursorPosition(3 + w / 2, h - 7);
			Console.WriteLine("{0}: 玩家与AI重叠", Util.overLapIcon);

			Console.ForegroundColor = ConsoleColor.White;
			Console.SetCursorPosition(3, h - 5);
			Console.WriteLine("按任意键开始扔骰子");
		}
		#endregion

		#region 结束场景逻辑
		//static void EndScene(int w, int h, ref E_SceneType nowSceneType)
		//{
		//	Console.SetCursorPosition(w / 2 - 10, 9);
		//	Console.ForegroundColor = ConsoleColor.Yellow;
		//	Console.WriteLine("---按 f/F 键确认---");
		//	Console.SetCursorPosition(w / 2 - 15, 11);
		//	Console.WriteLine("---输入没反应？记得切换输入法---");
		//	Console.SetCursorPosition(w / 2 - 10, 12);
		//	Console.WriteLine("---w/a/s/d进行移动---");

		//	Console.ForegroundColor = ConsoleColor.White;
		//	Console.SetCursorPosition(w / 2 - 5, 3);
		//	Console.WriteLine("Game  Over");
		//	int selectItem = 0;
		//	bool isOver = false;
		//	while (true)
		//	{
		//		Console.ForegroundColor = selectItem == 0 ? ConsoleColor.Red : ConsoleColor.White;
		//		if (selectItem == 0)
		//		{
		//			Console.SetCursorPosition(w / 2 - 7, 5);
		//			Console.WriteLine("->返回主菜单");
		//		}
		//		else
		//		{
		//			Console.SetCursorPosition(w / 2 - 7, 5);
		//			Console.WriteLine("  返回主菜单");
		//		}
		//		Console.
		//		ForegroundColor = selectItem == 1 ? ConsoleColor.Red : ConsoleColor.White;
		//		if (selectItem == 1)
		//		{
		//			Console.SetCursorPosition(w / 2 - 6, 7);
		//			Console.WriteLine("->退出游戏");
		//		}
		//		else
		//		{
		//			Console.SetCursorPosition(w / 2 - 6, 7);
		//			Console.WriteLine("  退出游戏");
		//		}


		//		int input = Console.ReadKey(true).KeyChar;
		//		switch (input)
		//		{
		//			case 'w':
		//			case 'W':
		//				selectItem -= 1;
		//				if (selectItem < 0)
		//				{
		//					selectItem = 1;
		//				}
		//				break;
		//			case 's':
		//			case 'S':
		//				selectItem += 1;
		//				selectItem %= 2;
		//				break;
		//			case 'f':
		//			case 'F':
		//				if (selectItem == 0)
		//				{
		//					nowSceneType = E_SceneType.Start;
		//					isOver = true;
		//				}
		//				else if (selectItem == 1)
		//				{
		//					Environment.Exit(0);
		//				}
		//				else
		//				{
		//					Console.WriteLine("bug?");
		//				}
		//				break;
		//		}
		//		if (isOver) break;
		//	}
		//}
		#endregion
	}



	#region 5.格子结构体和格子枚举
	/// <summary>
	/// 场景枚举类型
	/// </summary>
	enum E_SceneType
	{
		/// <summary>
		/// 开始场景
		/// </summary>
		Start,
		/// <summary>
		/// 游戏场景
		/// </summary>
		Game,
		/// <summary>
		/// 结束场景
		/// </summary>
		End
	}
	/// <summary>
	/// 格子类型枚举类型
	/// </summary>
	enum E_CellType
	{
		/// <summary>
		/// 普通格子
		/// </summary>
		Normal,
		/// <summary>
		/// 炸弹格子
		/// </summary>
		Bomb,
		/// <summary>
		/// 暂停格子
		/// </summary>
		Pause,
		/// <summary>
		/// 隧道格子
		/// </summary>
		Tunnel,
		/// <summary>
		/// 空格子
		/// </summary>
		NullCellIcon
	}
	struct Vector2
	{
		public int x_;
		public int y_;
		public Vector2(int x, int y)
		{
			x_ = x;
			 y_ = y;
		}
	}
	struct Cell
	{
		public E_CellType type_;
		public string icon_;
		public Vector2 pos_;
		public ConsoleColor color_;
		public Cell(int x, int y, E_CellType type, string icon, ConsoleColor color)
		{
			pos_.x_ = x;
			pos_.y_ = y;
			type_ = type;
			icon_ = icon;
			color_ = color;
		}

		public void draw()
		{
			Console.SetCursorPosition(pos_.x_, pos_.y_);
			Console.ForegroundColor = color_;
			Console.Write(icon_);

			//Console.SetCursorPosition(pos_.x_, pos_.y_);
			//switch (type_)
			//{
			//	case E_CellType.Normal:
			//		break;
			//	case E_CellType.Bomb:
			//		Console.ForegroundColor = ConsoleColor.Red;
			//		break;
			//	case E_CellType.Pause:
			//		Console.ForegroundColor = ConsoleColor.Blue;
			//		break;
			//	case E_CellType.Tunnel:
			//		Console.ForegroundColor = ConsoleColor.DarkBlue;
			//		break;
			//	case E_CellType.NullCellIcon:
			//		break;
			//	default:
			//		break;
			//}
			//Console.Write(icon_);
		}
	}
	#endregion
	#region 地图类 初始思路
	//struct Map
	//{
	//	public Cell[,] cells_;
	//	public int width_;
	//	public int height_;
	//	public int normalPer;
	//	public int pausePer;
	//	public int bombPer;
	//	public int tunnelPer;

	//	public Map(int height, int width)
	//	{
	//		cells_ = new Cell[height, width];
	//		width_ = width;
	//		height_ = height;
	//		// 概率
	//		// 80 6 2 8 63
	//		//    8 3 10 80
	//		normalPer = 80;
	//		pausePer = 6;
	//		bombPer = 4;
	//		tunnelPer = 10;

	//	}
	//	public void Init()
	//	{
	//		for (int i = 0; i < height_; i++)
	//		{
	//			for (int j = 0; j < width_; j++)
	//			{
	//				cells_[i, j] =
	//					new Cell(
	//						Util.w / 2 - 10 + j * 2,
	//						3 + i,
	//						E_CellType.NullCellIcon,
	//						Util.GetCellIcon(E_CellType.NullCellIcon), ConsoleColor.Green);
	//			}
	//		}

	//		Random r = new Random();
	//		bool flag = true;
	//		bool odd = false;
	//		int select = -1;
	//		for (int i = 0; i < height_; i++)
	//		{
	//			odd = false;
	//			for (int j = 0; j < width_; j++)
	//			{
	//				int ii = i;
	//				int jj = j;
	//				if (i % 2 != 0)
	//				{
	//					odd = true;
	//					if (flag)
	//					{
	//						jj = width_ - 1;
	//					}
	//					else
	//					{
	//						jj = 0;
	//					}
	//					flag = !flag;
	//				}
	//				select = r.Next(1, 101);
	//				E_CellType type = E_CellType.Normal;
	//				if (select >= 1 && select <= normalPer)
	//				{
	//					type = E_CellType.Normal;
	//				}
	//				else if (select > normalPer && select <= normalPer + pausePer)
	//				{
	//					type = E_CellType.Pause;
	//				}
	//				else if (select > normalPer + bombPer && select <= normalPer + bombPer + tunnelPer)
	//				{
	//					type = E_CellType.Bomb;
	//				}
	//				else
	//				{
	//					type = E_CellType.Tunnel;
	//				}

	//				string icon = Util.GetCellIcon(type);
	//				cells_[ii, jj] = new Cell(Util.w / 2 - 10 + jj * 2, 3 + ii, type, icon, Util.GetCellColor(type));
	//				//cells_[ii, jj].type_ = type;
	//				//cells_[ii, jj].icon_ = icon;
	//				//cells_[ii, jj].color_ = Util.GetCellColor(type);

	//				if (odd) break;
	//			}

	//		}
	//	}
	#endregion
	#region 6.地图类
	struct Map
	{
		public Cell[] cells_;
		public Map(int x, int y, int num)
		{
			cells_ = new Cell[num];
			Random r = new Random();
			int rand;
			int idx_x = 0;
			int idx_y = 0;
			int step = 2;

			for (int i = 0; i < num; i++)
			 {
				rand = r.Next(1, 101);
				if (i == 0 || i == num - 1 || rand >= 0 && rand < 80)
				{
					cells_[i].type_ = E_CellType.Normal;
				}
				else if (rand >= 80 && rand < 87)
				{
					cells_[i].type_ = E_CellType.Bomb;
				}
				else if (rand >= 87 && rand < 94)
				{
					cells_[i].type_ = E_CellType.Pause;
				}
				else
				{
					cells_[i].type_ = E_CellType.Tunnel;
				}
				cells_[i].icon_ = Util.GetCellIcon(cells_[i].type_);
				cells_[i].color_ = Util.GetCellColor(cells_[i].type_);
				if (i == 0) { 
					cells_[i].icon_ = "起";
					cells_[i].color_ = ConsoleColor.DarkRed;
				}
				if (i == num - 1) { 
					cells_[i].icon_ = "终";
					cells_[i].color_ = ConsoleColor.DarkRed;
				}
				cells_[i].pos_ = new Vector2(x, y);

				if (idx_x == 10)
				{
					y++;
					idx_y++;
					if (idx_y == 2)
					{
						idx_x = 0;
						idx_y = 0;
						step = -step;
					}
				}
				else
				{
					x += step;
					idx_x++;
				}
			}
		}
		public void draw()
		{
			for (int i = 0; i < cells_.Length; i++)
			{
				cells_[i].draw();
			}
		}
	}
	#endregion
	#region 角色类 初始思路
	//struct Character
	//{
	//	public CharacterType type_;
	//	public string icon_;
	//	public Vector2 pos_;
	//	public ConsoleColor color_;
	//	public Character(CharacterType type, int x, int y, string icon, ConsoleColor color)
	//	{
	//		type_ = type;
	//		pos_.x_ = x;
	//		pos_.y_ = y;
	//		icon_ = icon;
	//		color_ = color;
	//	}
	//	public void Draw()
	//	{
	//		Console.SetCursorPosition(pos_.x_, pos_.y_);
	//		Console.ForegroundColor = color_;
	//		Console.Write(icon_);
	//	}
	//}
	#endregion
	#region 7.角色类和角色枚举
	enum CharacterType
	{
		Player,
		Ai
	}
	struct Character
	{
		public CharacterType type_;
		public string icon_;
		public int nowIndex_;
		public ConsoleColor color_;
		public bool isPause;
		public Character(CharacterType type, int nowIndex, string icon, ConsoleColor color)
		{
			type_ = type;
			nowIndex_ = nowIndex;
			icon_ = icon;
			color_ = color;
			isPause = false;
		}
		public void Draw(Map map)
		{
			Cell cell = map.cells_[nowIndex_];
			Console.SetCursorPosition(cell.pos_.x_, cell.pos_.y_);
			Console.ForegroundColor = color_;
			Console.Write(icon_);
		}
	}
	#endregion
	
}
